

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'point/regionminutes/index',
                    //add_url: 'point/regionminutes/add',
                    //edit_url: 'point/regionminutes/edit',
                    del_url: 'point/regionminutes/del',
                    multi_url: 'point/regionminutes/multi',
                    table: 'region_monitor_5minutes',
                }
            });
            
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'everyDay', title: __('Everyday'), operate:'RANGE', addclass:'datetimerange',defaultValue: dayTime+' 00:00:00 - '+dayTime+' 23:59:59'},
                        /*{field: 'reportType', title: __('Type'), searchList:reportTypeList,defaultValue:'region_monitor_day',formatter:function(data,full){
                                if(data == "region_monitor_5minutes"){
                                    return  '5分钟';
                                }else if(data == "region_monitor_day"){
                                    return '日表';
                                }else{
                                    return '月表';
                                }
                        }},*/
                        {field: 'tag.name', title: __('Region_tag_id'),placeholder: __('模糊查询'),operate: 'LIKE %...%'},
                        {field: 'subnetrata', title: __('本网化率(%)'),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(full.servicesoutflow==0||full.internetoutflow==0){
                               return '-';
                            }else{
                               return data.toFixed(2);
                            }
                        }},
                        {field: 'internetoutflow', title: __('互联网出口'+units),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return (data/divided).toFixed(2);
                            }
                        }},
                        {field: 'servicesoutflow', title: __('总服务流量'+units),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return (data/divided).toFixed(2);
                            }
                        }},
                        {field: 'exportrate', title: __('出口利用率(%)'),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(full.exportband==0||full.exportoutflow==0){
                               return '-';
                            }else{
                               return data.toFixed(2);
                            }
                        }},
                        {field: 'exportoutflow', title: __('出口使用量'+units),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return (data/divided).toFixed(2);
                            }
                        }},
                        {field: 'exportband', title: __('出口带宽(G)'),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return data.toFixed(2);
                            }
                        }},
                        {field: 'transrate', title: __('传输使用率(%)'),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(full.transband==0||full.transoutflow==0){
                               return '-';
                            }else{
                               return data.toFixed(2);
                            }
                        }},
                        {field: 'transoutflow', title: __('传输使用量'+units),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return (data/divided).toFixed(2);
                            }
                        }},
                        {field: 'transband', title: __('传输带宽(G)'),placeholder: __('数字'), operate:'BETWEEN',formatter:function(data,full){
                            if(data==0){
                               return '-';
                            }else{
                               return data.toFixed(2);
                            }
                        }},
                        // {field: 'a.comment',title: __('备注'),placeholder: __('模糊查询'),operate: 'LIKE %...%',formatter:function(value,row,index){
                        //     return row.comment;
                        // }},
                        {field: 'counttime', title: __('更新时间'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        /*{field: 'counttime', title: __('Counttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},*/
                        /*{field: 'hourtime', title: __('Hourtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'monthly', title: __('Monthly')},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
            });
            //当表格数据加载完成时
            /*table.on('load-success.bs.table', function (e, data) {
               if(document.getElementsByName("reportType")[0].options.length > 3){//去掉请选择
                    document.getElementsByName("reportType")[0].options.remove(0); 
               }
            });*/
            
            // 为表格绑定事件
            Table.api.bindevent(table);
            $(".btn-default").click(function(obj){
                  if($(this).html()=="重置"){
                     location.reload();
                  }
            });
            $(document).on("click", ".update-day", function () {
                $.ajax({
                    url: 'regionminutes/update_day',
                    type:'post',
                    data: {},
                    dataType:'json',
                    beforeSend: function () {
                             i = layer.msg('更新中请稍等...', {icon: 16,shade: [0.5, '#393D49'],scrollbar: false,offset:'50%',time:60*1000});
                        },
                    success:function(json){
                        layer.close(i);
                        layer.alert(json.msg);
                        $(".btn-refresh").click();
                    }
                });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});